package com.loadburn.heron.storage;

import com.loadburn.heron.cache.ICache;
import com.loadburn.heron.storage.config.EntityMetadataConfig;
import com.loadburn.heron.storage.sql.Page;
import com.loadburn.heron.storage.sql.Query;
import com.loadburn.heron.storage.transaction.InTransaction;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @author slacrey (scstlinfeng@yahoo.com)
 *         Date: 13-12-11
 */
public interface EntityStorage {

    public <T> boolean save(T entity) throws SQLException;

    public <T> boolean remove(T entity) throws SQLException;

    public <T> boolean update(T entity, Object primaryKey) throws SQLException;

    public <T> T findOne(Class<T> entityClass, Object primaryKey) throws SQLException;

    public <T> T findOne(Class<T> entityClass, String name, Map<String, Object> nameParams) throws SQLException;

    public <T> List<T> find(Class<T> entityClass) throws SQLException;

    public <T> List<T> find(Class<T> entityClass, String name, Map<String, Object> nameParams) throws SQLException;

    public <T> List<T> find(Class<T> entityClass, int page, int size) throws SQLException;

    public <T> List<T> find(Class<T> entityClass, String name, Map<String, Object> nameParams, int page, int size) throws SQLException;

    public <T> Page<T> findPageable(Class<T> entityClass, int page, int size) throws SQLException;

    public <T> Page<T> findPageable(Class<T> entityClass, String name, Map<String, Object> nameParams, int page, int size) throws SQLException;

    public <T> int count(Class<T> entityClass) throws SQLException;

    public <T> int count(Class<T> entityClass, String name, Map<String, Object> nameParams) throws SQLException;

    public Object getDelegate();

    public void close();

    public boolean isOpen();

    public <T> Query createQuery(Class<T> clazz, String sqlQuery);

    public <T> Query createNamedQuery(Class<T> clazz, String name);

    public InTransaction getTransaction();

    public ICache getCache();

    public Connection getConnection();

    public EntityMetadataConfig getMetadataConfig();

}
